package mqtt.handler;

import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.client.MqttCallback;
import org.eclipse.paho.mqttv5.client.MqttDisconnectResponse;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import org.eclipse.paho.mqttv5.common.packet.MqttProperties;

public class DefaultMqttCallback implements MqttCallback {
    @Override
    public void disconnected(MqttDisconnectResponse disconnectResponse) {
        System.out.println("Disconnected: " + disconnectResponse.getReasonString());
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) {
        System.out.println("Message received: " + new String(message.getPayload()));
    }

    @Override
    public void deliveryComplete(IMqttToken token) {
        // 消息传递完成（QoS 1/2时触发）
    }

    @Override
    public void connectComplete(boolean reconnect, String serverURI) {
        System.out.println(reconnect ? "Reconnected" : "Connected");
    }

    @Override
    public void authPacketArrived(int reasonCode, MqttProperties properties) {
        // 认证包处理
    }

	@Override
	public void mqttErrorOccurred(MqttException exception) {
		 System.err.println("MQTT Error: " + exception.getMessage());
		
	}
}


